/**
 * 
 */
package com.alstudio.service;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.IBinder;

import com.alstudio.app.LocalEnv;
import com.alstudio.net.EventHandler.XmppEventHandler;
import com.alstudio.net.protocol.xmpp.XmppAdapter;
import com.alstudio.net.protocol.xmpp.data.XmppData;
import com.alstudio.utils.android.net.ALNetworkReceiver;
import com.alstudio.utils.notification.NoticeItem;

/**
 * @author Alonso Lee
 * 
 */
public class BackgroundService extends Service {

	private XmppData data;
	private XmppEventHandler mXmppEventHandler;
	private NoticeItem curItem;
	private ALNetworkReceiver mConnectionReceiver = new ALNetworkReceiver();

	@Override
	public void onStart(Intent intent, int startId) {
		// TODO Auto-generated method stub
		super.onStart(intent, startId);
		initService();

	}

	private void initService() {
		mXmppEventHandler = new XmppEventHandler();
		LocalEnv.adapter = new XmppAdapter(mXmppEventHandler);

//		data = new XmppData("112.124.53.184", "5222", "ai", 50);
//		data.setUsername("235517");
//		data.setPassword("123456");
//		
////		data = new XmppData("116.254.203.117", "5555", "mk", 50);
////		data.setUsername("200278");
////		data.setPassword("pppppp");
//		
//		LocalEnv.adapter.xmppLogin(data);

		IntentFilter filter = new IntentFilter();
		filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
		registerReceiver(mConnectionReceiver, filter);
	}

	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		unregisterReceiver(mConnectionReceiver);
	}
	

}
